package com.service.bank.controller;

import com.client.model.pojo.bank.DepositRecord;
import com.client.model.vo.common.Result;
import com.service.bank.service.DepositRecordService;
import com.service.bank.service.DepositService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @Author：刘文举
 * @DateTime： 2024/4/6 17:42
 * @PackageName: com.service.bank.controller
 * @ClassName: AdminBankController
 */

@RestController
@RequestMapping("/airui/admin/api")
public class AdminBankController {



    @Autowired
    private DepositRecordService depositRecordService;

    @Autowired
    private DepositService depositService;


    /**
     * 申请通过
     */
    @GetMapping("/approved")
    @Operation(summary = "管理员确认申请")
    public Result approved(Long id) {
        DepositRecord optById = depositRecordService.getOptById(id).get();
        if (optById.getIsType() == 0) {
            depositService.currentTofixed(optById.getBankCard(), optById.getIsType(), optById.getBalance());
        }else {
            depositService.fixedToCurrent(optById.getBankCard(),optById.getRemark(),optById.getBalance());
        }
        optById.setStatus(1);
        depositRecordService.updateById(optById);

        return Result.build(null, 200, "确认申请成功");
    }

    /**
     * 申请不通过
     *
     */
    @GetMapping("/refuse")
    @Operation(summary = "管理员取消申请")
    public Result refuse(Long id) {
        return depositRecordService.refuse(id);
    }


}
